import api from '../../utils/api';

Page({
  data: {
    form: {
      title: '',
      description: '',
      startTime: '',
      endTime: '',
      eventType: 'personal'
    },
    showConflictDialog: false,
    conflicts: []
  },

  async handleSubmit() {
    try {
      const { form } = this.data;
      await api.addEvent(form);
      
      wx.showToast({
        title: '添加成功',
        icon: 'success'
      });
      
      wx.navigateBack();
    } catch (error) {
      if (error.conflicts) {
        // 显示冲突对话框
        this.setData({
          showConflictDialog: true,
          conflicts: error.conflicts
        });
      } else {
        wx.showToast({
          title: error.message || '添加失败',
          icon: 'none'
        });
      }
    }
  }
});